# -*- coding: utf-8 -*-            
# @Author : chenliang
# @Time : 2024/1/5 13:24

import time

from Case.python_ui.Common.basepage import Basepage
from Case.python_ui.PageLocate.user_product_network_locator import ProductNetworkLocator
from Case.python_ui.Pageobject.admin_product_managent_pages import ProductManagementPages
from Case.python_ui.Pageobject.user_product_computing import ProductComputing
from Case.python_ui.PageLocate.product_management_locator import ProductManagementLocator
from Case.python_ui.Common.excel import excel
from selenium.common.exceptions import NoSuchElementException
import random

from selenium.common.exceptions import StaleElementReferenceException
import time, pytest
from Case.python_ui.PageLocate.organization_locator import OrganizationLocator
from Case.python_ui.PageLocate.user_orders_locator import OrdersLocator
from Case.python_ui.Common.commontool import CommonTool
from Case.python_ui.Test_data.usergroup_data import UserGroup
import re
from datetime import datetime


class ProductNetwork(Basepage):

    """公共方法"""
    # 等待页面加载转动
    def wait_web_page_rotate(self, time=100):
        doc = '等待页面加载转动图标'
        try:
            self.wait_elevisble(ProductNetworkLocator.wait_for_pay, doc, time)
            self.wait_eleinvisble(ProductNetworkLocator.wait_for_pay, doc, time)
        except:
            pass

    # 清空Status 1
    def clear_status(self, num, product='pp', if_choose=False):
        doc = "清空Order Type 1，Order Status 2，Billing Method 3"
        if_disabled = False
        if num == 1:
            js_object = 'document.getElementsByClassName("antd4-table-content")[1].scrollTo(1000,10000)'
            self.excute_js(js_object);
            addr = ProductNetworkLocator.click_status
        for i in range(3):
            try:
                self.wait_elevisble(addr, doc)
                self.move_mouse_to_click_element(addr, doc)
                time.sleep(5)
                if_disabled = self.is_element_disabled(OrdersLocator.reset)
                print(if_disabled)
                break
            except NoSuchElementException:
                continue
        if if_disabled:
            self.move_mouse_to_click_element(OrdersLocator.reset, doc)
        time.sleep(2)
        if if_choose == True:
            self.wait_elevisble(OrdersLocator.product, doc)
            product_list = self.get_elements(OrdersLocator.product, doc)
            for i in product_list:
                if i.text == product:
                    i.click()
                    break
            time.sleep(5)
        self.wait_elevisble(OrdersLocator.product_ok, doc)
        self.click_element(OrdersLocator.product_ok, doc)
        self.wait_web_page_rotate(10)

    """
    
    """

    # 进入myresource页面
    def enter_my_resource_page_new(self):
        time.sleep(2)
        doc = "进入myresource页面"
        for i in range(3):
            try:
                self.scroll_bar_operation(ProductManagementLocator.click_myresource)
                self.click_element(ProductManagementLocator.click_myresource, doc)
                break
            except:
                self.scroll_bar_operation(ProductManagementLocator.click_order_management)
                self.click_element(ProductManagementLocator.click_order_management, doc)
                time.sleep(2)
                self.wait_elevisble(ProductManagementLocator.click_myresource, doc)
                self.click_element(ProductManagementLocator.click_myresource, doc)
                time.sleep(5)
                continue
        time.sleep(10)

    # 进入myresource页面
    def enter_my_resource_page(self):
        doc = '进入user端的myresource页面'
        for i in range(3):
            try:
                self.wait_elevisble(ProductManagementLocator.my_resource_tab, doc)
                self.click_element(ProductManagementLocator.my_resource_tab, doc)
                break
            except:
                self.refresh_page()
                continue

        time.sleep(5)

    # 进入My Resource中的Network页面
    def enter_network(self):
        doc = '进入My Resource中的Network页面'
        # ProductManagementPages.enter_my_resource_page(self)
        self.enter_my_resource_page()
        time.sleep(5)
        ProductComputing.click_my_resource_tab(self, 'Network')
        # self.wait_elevisble(ProductNetworkLocator.network_page, doc)
        # self.move_mouse_to_click_element(ProductNetworkLocator.network_page, doc)
        time.sleep(2)

    # 进入 NAT Gateways管理页面
    def enter_nat_gateways(self, page):
        doc = '进入NAT Gateways'
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.first_id, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.first_id, doc)
        time.sleep(10)
        content = ''
        for i in range(3):
            try:
                # 切换frame
                self.driver.switch_to.frame(self.get_element(ProductNetworkLocator.iframe, doc))
                time.sleep(5)
                self.wait_elevisble(ProductNetworkLocator.check_nat_gateways, doc)
                content = self.get_element(ProductNetworkLocator.check_nat_gateways, doc).text
                break
            except:
                time.sleep(10)
                continue
        assert content == page

    # 进入release 页面并确认释放
    def enter_nat_gateways_release(self):
        doc = '进入nat_gateways_release页面'
        time.sleep(5)
        self.wait_elevisble(ProductNetworkLocator.first_setting, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.first_setting,doc)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.release, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.release, doc)
        time.sleep(10)
        self.switch_to_new_window()
        time.sleep(5)
        for i in range(3):
            try:
                time.sleep(2)
                self.wait_elevisble(ProductNetworkLocator.setting_delete, doc)
                self.click_element(ProductNetworkLocator.setting_delete, doc)
                time.sleep(1)
                self.wait_elevisble(ProductNetworkLocator.yes_delete, doc)
                self.click_element(ProductNetworkLocator.yes_delete, doc)
                self.wait_elevisble(ProductNetworkLocator.sure, doc)
                text = self.get_element(ProductNetworkLocator.sure, doc).text
                if text == 'Delete Successfully':
                    break
                time.sleep(5)
            except:
                time.sleep(5)
                continue
        time.sleep(2)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        a = ''
        for i in range(3):
            time.sleep(5)
            self.wait_elevisble(ProductNetworkLocator.search, doc)
            self.click_element(ProductNetworkLocator.search, doc)
            try:
                self.wait_elevisble(ProductNetworkLocator.wait_for_pay, doc)
                self.wait_eleinvisble(ProductNetworkLocator.wait_for_pay, doc)
            except:
                pass
            self.wait_elevisble(ProductNetworkLocator.first_status, doc)
            a = self.get_element(ProductNetworkLocator.first_status, doc).text
            if a == 'Invalid':
                break
        text = '实际值 ：' + a + '预期值：' + 'Invalid 被删除'
        assert a == 'Invalid', text

    # 查询NAT Gateways name
    def search_nat_name(self, name):
        doc = '查询NAT Gateways name'
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.search_by, doc)
        self.send_keys(ProductNetworkLocator.search_by, name, doc)
        self.wait_elevisble(ProductNetworkLocator.nat_search, doc)
        self.click_element(ProductNetworkLocator.nat_search, doc)
        time.sleep(2)

    # delete NAT Gateways资源
    def delete_nat_gateways(self, name):
        doc = '删除nat gateways资源'
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.setting, doc)
        self.move_mouse_to_element(ProductNetworkLocator.setting)
        self.wait_elevisble(ProductNetworkLocator.delete, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.delete, doc)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.confirmed, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.submit, doc)
        time.sleep(2)
        # 等待删除状态变更
        for i in range(6):
            try:
                self.wait_elevisble(ProductNetworkLocator.nat_search, doc)
                self.click_element(ProductNetworkLocator.nat_search, doc)
                time.sleep(2)
                self.wait_elevisble(ProductNetworkLocator.total, doc)
                total = self.get_element(ProductNetworkLocator.total, doc).text
                if total == 'Total 0':
                    break
            except:
                time.sleep(10)
                continue

    # 判断资源 NAT Gateways是否在控制台删除
    def if_nat_gateways_deleted(self, name=''):
        doc = '判断nat gateways资源是否在控制台删除'
        time.sleep(2)
        # 等待删除状态变更
        for i in range(6):
            try:
                self.wait_elevisble(ProductNetworkLocator.nat_search, doc)
                self.click_element(ProductNetworkLocator.nat_search, doc)
                time.sleep(2)
                self.wait_elevisble(ProductNetworkLocator.total, doc)
                total = self.get_element(ProductNetworkLocator.total, doc).text
                if total == 'Total 0':
                    break
            except:
                time.sleep(10)
                continue

    # 根据product 查询
    def select_term(self, term, elements):
        doc = '点击network页面的查询条件'
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.select_term, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.select_term, doc)
        time.sleep(5)
        self.wait_elevisble(ProductNetworkLocator.select_list, doc)
        select_list = self.get_elements(ProductNetworkLocator.select_list, doc)
        print(select_list)
        for i in select_list:
            if i.text == term:
                i.click()
                break
        time.sleep(5)
        self.wait_elevisble(ProductNetworkLocator.search_product, doc)
        self.send_keys(ProductNetworkLocator.search_product, elements, doc)
        time.sleep(2)
        # self.wait_elevisble(ProductNetworkLocator.visibility_of_judgment_product, doc)
        self.keyboard_event_enter(ProductNetworkLocator.search_product, doc)  # 按空格键
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.search, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.search, doc)
        time.sleep(2)
        self.wait_web_page_rotate(10)
        try:
            timeout_alert = self.wait_elevisble(ProductNetworkLocator.timeout_alert, doc, timeout=10).text
            if timeout_alert == 'Timeout, please try again.':
                self.save_screen(doc)
                assert 1 == 2
        except:
            pass
        select_list = self.get_elements(ProductNetworkLocator.search_list, doc)
        if len(select_list) > 0:
            for i in select_list:
                if i.text != '':
                    # print(i.text+':'+elements)
                    assert i.text == elements
                    # print('num：'+i.text)
        time.sleep(2)

    # 根据 Organization进行查询
    def select_organization(self, org):
        doc = 'network页面根据organization进行查询'
        select_list = []
        for i in range(3):
            try:
                self.wait_elevisble(ProductNetworkLocator.search_org, doc)
                self.move_mouse_to_click_element(ProductNetworkLocator.search_org, doc)
                time.sleep(5)
                self.wait_elevisble(ProductNetworkLocator.organization_list, doc)
                select_list = self.get_elements(ProductNetworkLocator.organization_list, doc)
                print(select_list)
            except:
                continue
        num = 0
        for i in select_list:
            if i.text == org:
                num = num + 1
                i.click()
                break
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.search, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.search, doc)
        time.sleep(2)
        select_list = self.get_elements(ProductNetworkLocator.search_org_list, doc)
        # 不为父亲节点的时候进行交验
        if len(select_list) > 0 and num != 1:
            for i in select_list:
                if i.text != '':
                    # print(i.text+':'+elements)
                    assert i.text == org
                    # print('num：'+i.text)
        time.sleep(2)

    # 创建一个NAT Gateways
    def create_nat_gateways(self):
        doc = '创建一个NAT Gateways'
        self.enter_network()
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(3)
        ProductManagementPages.get_prod_name_to_click(self, 'NAT Gateways')
        time.sleep(3)
        self.move_mouse_to_element(ProductManagementLocator.my_resource_tab)  # 鼠标移开，防止误点击
        self.switch_to_new_window()
        # 等待页面加载
        self.wait_web_page_rotate(10)
        self.wait_elevisble(ProductNetworkLocator.input_name, doc)
        random_number = random.randint(1, 100000)
        name = 'auto_named_nat' + str(random_number)
        self.send_keys(ProductNetworkLocator.input_name, name, doc)
        self.wait_elevisble(ProductNetworkLocator.vpc, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.vpc, doc)
        self.wait_elevisble(ProductNetworkLocator.select_vpc, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.select_vpc, doc)
        time.sleep(2)
        self.excute_js("window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(2)
        # self.wait_elevisble(ProductNetworkLocator.read_and_agree, doc)
        # self.move_mouse_to_click_element(ProductNetworkLocator.read_and_agree, doc)
        self.wait_elevisble(ProductNetworkLocator.buy, doc)
        self.click_element(ProductNetworkLocator.buy, doc)
        try:
            self.wait_elevisble(ProductNetworkLocator.wait_for_pay, doc)
            self.wait_eleinvisble(ProductNetworkLocator.wait_for_pay, doc)
        except:
            pass
        self.wait_elevisble(ProductNetworkLocator.read_and_agree, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.read_and_agree, doc)
        self.wait_elevisble(ProductNetworkLocator.pay, doc)
        self.click_element(ProductNetworkLocator.pay, doc)
        time.sleep(5)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        return name

    # 创建一个vpn
    def create_vpn_gateways(self):
        doc = '创建一个VPN Gateways'
        """
        进入创建vpn页面
        """
        self.enter_network()
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        ProductManagementPages.get_prod_name_to_click(self, 'VPN Gateways')
        time.sleep(10)
        self.move_mouse_to_element(ProductManagementLocator.my_resource_tab)  # 鼠标移开，防止误点击
        self.switch_to_new_window()
        time.sleep(5)
        """
        vpn页面按钮操作
        """
        self.wait_elevisble(ProductNetworkLocator.organization, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.organization, doc)
        time.sleep(5)
        self.wait_elevisble(ProductNetworkLocator.organization_list, doc)
        organization_list = []
        organization_list = self.get_elements(ProductNetworkLocator.organization_list, doc)
        random_value = organization_list[0]
        organization = random_value.text
        print('选择的organization值:', random_value.text)
        time.sleep(5)
        random_value.click()
        time.sleep(5)
        self.wait_elevisble(ProductNetworkLocator.gateway_name, doc)
        random_number = random.randint(1, 100000)
        name = 'auto_named_vpn' + str(random_number)
        self.send_keys(ProductNetworkLocator.gateway_name, name, doc)
        time.sleep(5)
        self.wait_elevisble(ProductNetworkLocator.click_vpc_vswitch1, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.click_vpc_vswitch1, doc)
        time.sleep(5)
        self.wait_elevisble(ProductNetworkLocator.vpc_vswitch_list1, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.vpc_vswitch_list1, doc)
        time.sleep(5)
        self.wait_elevisble(ProductNetworkLocator.click_vpc_vswitch2, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.click_vpc_vswitch2, doc)
        time.sleep(5)
        self.wait_elevisble(ProductNetworkLocator.vpc_vswitch_list2, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.vpc_vswitch_list2, doc)
        time.sleep(5)
        self.wait_web_page_rotate(10)
        self.wait_elevisble(ProductNetworkLocator.buy, doc)
        self.click_element(ProductNetworkLocator.buy, doc)
        self.wait_web_page_rotate(30)  # 等待页面转圈
        self.wait_elevisble(ProductNetworkLocator.agree, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.agree, doc)
        self.wait_elevisble(ProductNetworkLocator.pay, doc)
        self.click_element(ProductNetworkLocator.pay, doc)
        time.sleep(5)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        print(organization, name)
        return organization, name

    # 续订VPN
    def continue_renew(self):
        doc = '续订VPN'
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.first_renew, doc)
        self.click_element(ProductNetworkLocator.first_renew, doc)
        time.sleep(5)
        self.switch_to_new_window()
        # self.wait_elevisble(ProductNetworkLocator.read_and_agree, doc)
        # self.move_mouse_to_click_element(ProductNetworkLocator.read_and_agree, doc)
        self.wait_elevisble(ProductNetworkLocator.new_expiration_date, doc)
        new_expiration_date = self.get_element(ProductNetworkLocator.new_expiration_date, doc).text
        self.wait_elevisble(ProductNetworkLocator.buy, doc)
        self.click_element(ProductNetworkLocator.buy, doc)
        self.wait_web_page_rotate(5)
        self.wait_elevisble(ProductNetworkLocator.read_and_agree, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.read_and_agree, doc)
        self.wait_elevisble(ProductNetworkLocator.pay, doc)
        self.click_element(ProductNetworkLocator.pay, doc)
        for i in range(3):
            try:
                self.wait_elevisble(ProductNetworkLocator.pay_success, doc)
                pay_success_text = self.get_element(ProductNetworkLocator.pay_success, doc).text
                if pay_success_text == 'Payment Successful':
                    break
            except:
                time.sleep(5)
                continue
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        a = ''
        for i in range(3):
            time.sleep(5)
            self.wait_elevisble(ProductNetworkLocator.search, doc)
            self.click_element(ProductNetworkLocator.search, doc)
            self.wait_elevisble(ProductNetworkLocator.first_expired_time, doc)
            a = self.get_element(ProductNetworkLocator.first_expired_time, doc).text
            if a == new_expiration_date:
                break
        assert a == new_expiration_date

    """
         VPC
    """

    # 进入vpc控制台页面
    def enter_vpc_gateways(self):
        doc = '进入vpc控制台页面'
        """
        进入创建vpn页面
        """
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.vpc_create, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.vpc_create, doc)
        # ProductManagementPages.get_prod_name_to_click(self, 'Virtual Private Clouds')
        time.sleep(30)
        for i in range(3):
            try:
                self.driver.switch_to.frame(self.get_element(ProductNetworkLocator.iframe, doc))
                self.wait_elevisble(ProductNetworkLocator.check_vpc_success, doc)
                text = self.get_element(ProductNetworkLocator.check_vpc_success, doc).text
                if text == 'Virtual Private Cloud':
                    break
            except:
                continue
        # self.switch_to_new_window()
        time.sleep(5)
        self.wait_elevisble(ProductNetworkLocator.vpc_menu, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.vpc_menu, doc)
        time.sleep(2)
        content = ''
        for i in range(3):
            try:
                time.sleep(5)
                # 切换frame
                # self.driver.switch_to.frame(self.get_element(ProductNetworkLocator.iframe, doc))
                self.wait_elevisble(ProductNetworkLocator.check_nat_gateways, doc)
                content = self.get_element(ProductNetworkLocator.check_nat_gateways, doc).text
                print('****:', content)
                break
            except:
                time.sleep(10)
                continue
        assert content == 'Virtual Private Clouds'
        time.sleep(5)

    # 新增VPC
    def create_vpc(self):
        doc = '新增VPC'
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.create_vpc_button, doc)
        self.click_element(ProductNetworkLocator.create_vpc_button, doc)
        for i in range(3):
            try:
                self.wait_elevisble(ProductNetworkLocator.check_vpc_page_success, doc)
                if self.get_element(ProductNetworkLocator.check_vpc_page_success, doc).text == 'Create VPC':
                    break
            except:
                continue
        time.sleep(5)
        self.wait_elevisble(ProductNetworkLocator.click_org, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.click_org, doc)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.search_vpc_org_list, doc)
        vpc_org_list = []
        vpc_org_list = self.get_elements(ProductNetworkLocator.search_vpc_org_list, doc)
        random_value = random.choice(vpc_org_list)
        organization = random_value.text
        random_value.click()
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.input_vpc_name, doc)
        random_number = random.randint(1, 100000)
        name = 'vpc_name' + str(random_number)
        self.send_keys(ProductNetworkLocator.input_vpc_name, name, doc)
        time.sleep(12)
        self.wait_elevisble(ProductNetworkLocator.create_vpc_button, doc)
        self.click_element(ProductNetworkLocator.create_vpc_button, doc)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.click_ok, doc)
        self.click_element(ProductNetworkLocator.click_ok, doc)
        time.sleep(2)
        for i in range(3):
            try:
                self.wait_elevisble(ProductNetworkLocator.check_vpc_success, doc)
                if self.get_element(ProductNetworkLocator.check_vpc_success, doc).text == 'Virtual Private Cloud':
                    break
            except:
                continue
        print('******:', organization, name)
        return organization, name
        time.sleep(5)

    # 根据vpc_name查询vpc
    def search_vpc_by_name(self, vpc_name=''):
        doc = '根据vpc_name进行查询'
        time.sleep(2)
        for i in range(3):
            try:
                self.wait_elevisble(ProductNetworkLocator.check_vpc_success, doc)
                if self.get_element(ProductNetworkLocator.check_vpc_success, doc).text == 'Virtual Private Cloud':
                    break
            except:
                continue
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.input_vpc_name, doc)
        self.send_keys(ProductNetworkLocator.input_vpc_name, vpc_name, doc)
        self.wait_elevisble(ProductNetworkLocator.click_vpc_search, doc)
        self.click_element(ProductNetworkLocator.click_vpc_search, doc)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.if_total, doc)
        if vpc_name != '':
            assert self.get_element(ProductNetworkLocator.if_total, doc).text == 'Total 1'

    # 查看vpc详情
    def check_vpn_page_detail(self):
        doc = '检查vpc详细页面'
        time.sleep(2)
        vpc_list = {}
        self.wait_elevisble(ProductNetworkLocator.find_first_vpc_id, doc)
        vpc_list['vpc_id'] = self.get_element(ProductNetworkLocator.find_first_vpc_id, doc).text
        self.wait_elevisble(ProductNetworkLocator.find_first_vpc_name, doc)
        vpc_list['vpc_name'] = self.get_element(ProductNetworkLocator.find_first_vpc_name, doc).text
        self.wait_elevisble(ProductNetworkLocator.find_first_vpc_ip, doc)
        vpc_list['vpc_ip'] = self.get_element(ProductNetworkLocator.find_first_vpc_ip, doc).text
        self.wait_elevisble(ProductNetworkLocator.find_first_org, doc)
        vpc_list['vpc_org'] = self.get_element(ProductNetworkLocator.find_first_org, doc).text
        self.wait_elevisble(ProductNetworkLocator.find_first_resource_set, doc)
        vpc_list['vpc_resource_set'] = self.get_element(ProductNetworkLocator.find_first_resource_set, doc).text
        print(vpc_list)
        self.wait_elevisble(ProductNetworkLocator.click_first_management, doc)
        self.click_element(ProductNetworkLocator.click_first_management, doc)
        time.sleep(5)
        self.wait_elevisble(ProductNetworkLocator.vpc_detail_vpc_id, doc)
        assert vpc_list['vpc_id'] == self.get_element(ProductNetworkLocator.vpc_detail_vpc_id, doc).text
        self.wait_elevisble(ProductNetworkLocator.vpc_detail_vpc_name, doc)
        assert vpc_list['vpc_name'] == self.get_element(ProductNetworkLocator.vpc_detail_vpc_name, doc).text
        self.wait_elevisble(ProductNetworkLocator.vpc_detail_vpc_ip, doc)
        assert vpc_list['vpc_ip'] == self.get_element(ProductNetworkLocator.vpc_detail_vpc_ip, doc).text
        self.wait_elevisble(ProductNetworkLocator.vpc_detail_vpc_org, doc)
        assert vpc_list['vpc_org'] == self.get_element(ProductNetworkLocator.vpc_detail_vpc_org, doc).text
        self.wait_elevisble(ProductNetworkLocator.vpc_detail_vpc_resource_set, doc)
        assert vpc_list['vpc_resource_set'] == self.get_element(ProductNetworkLocator.vpc_detail_vpc_resource_set,
                                                                doc).text
        time.sleep(5)

    # 删除vpc
    def delete_vpc(self, vpc_name=''):
        doc = '删除vpc'
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.click_first_delete, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.click_first_delete, doc)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.click_delete_ok, doc)
        self.move_mouse_to_click_element(ProductNetworkLocator.click_delete_ok, doc)
        time.sleep(10)
        self.wait_elevisble(ProductNetworkLocator.input_vpc_name, doc)
        self.send_keys(ProductNetworkLocator.input_vpc_name, vpc_name, doc)
        self.wait_elevisble(ProductNetworkLocator.click_vpc_search, doc)
        self.click_element(ProductNetworkLocator.click_vpc_search, doc)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.if_total, doc)
        if vpc_name != '':
            assert self.get_element(ProductNetworkLocator.if_total, doc).text == 'Total 0'

    """
       补充my resource部分用例 
    """

    # 通过产品名称精确查询并交验
    def check_create_new_product_list_select(self, search_str):
        doc = '检查product搜索'
        self.wait_elevisble(ProductNetworkLocator.move_create_new, doc)
        self.move_mouse_to_element(ProductNetworkLocator.move_create_new)
        time.sleep(2)
        product_list_old = self.get_elements(ProductNetworkLocator.product_list, doc)
        assert len(product_list_old) > 1
        self.wait_elevisble(ProductNetworkLocator.input_product, doc)
        self.send_keys(ProductNetworkLocator.input_product, search_str, doc)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.product_list, doc)
        product_list = self.get_elements(ProductNetworkLocator.product_list, doc)
        print('product_list:', product_list, type(product_list))
        assert len(product_list) == 1
        assert product_list[0].text == search_str

    # 通过产品名称模糊查询并交验
    def check_create_new_product_list_select2(self, search_str):
        doc = '通过产品名称模糊查询并交验'
        self.wait_elevisble(ProductNetworkLocator.move_create_new, doc)
        self.move_mouse_to_element(ProductNetworkLocator.move_create_new)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.input_product, doc)
        self.send_keys(ProductNetworkLocator.input_product, search_str, doc)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.product_list, doc)
        product_list = self.get_elements(ProductNetworkLocator.product_list, doc)
        for i in range(len(product_list)):
            text = '查询值：' + search_str + '查询出的值：' + product_list[i - 1].text
            assert search_str.lower() in product_list[i - 1].text.lower(), text

    """
       admin页面方法 Product Management
    """

    def enter_product_management(self):
        doc = '点击菜单进入Product Category页面'
        time.sleep(10)
        # self.wait_elevisble(ProductNetworkLocator.product_management, doc)
        self.scroll_bar_operation(ProductNetworkLocator.product_management)
        self.wait_elevisble(ProductNetworkLocator.product_management_parent_node, doc)
        class_value = self.get_attribute(ProductNetworkLocator.product_management_parent_node, 'class', doc)
        print(class_value)
        if class_value == 'antd4-menu-submenu antd4-menu-submenu-inline':
            self.click_element(ProductNetworkLocator.product_management, doc)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.product_category, doc)
        self.click_element(ProductNetworkLocator.product_category, doc)
        time.sleep(2)
        self.wait_elevisble(ProductNetworkLocator.category_list, doc)
        category_list = []
        category_list = self.get_elements(ProductNetworkLocator.category_list, doc)
        category_list_text = []
        for i in category_list:
            category_list_text.append(i.text)
        print(category_list_text)
        return category_list_text
